package com.intelligent.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.service.ProductionReportingService;
import com.intelligent.pojo.ProductionReporting;

import java.util.Map;

@RestController
@RequestMapping("/productionReporting")
public class ProductionReportingController {
    @Autowired
    private ProductionReportingService productionReportingService;

    @GetMapping("/page")
    public IPage<Map<String, Object>> page(@RequestParam(defaultValue = "1") long pageNum,
                                           @RequestParam(defaultValue = "10") long pageSize,
                                           @RequestParam(required = false) String reportNo,
                                           @RequestParam(required = false) String processName,
                                           @RequestParam(required = false) String processCode,
                                           @RequestParam(required = false) String relatedWorkOrder,
                                           @RequestParam(required = false) String username,
                                           @RequestParam(required = false) String workGroup,
                                           @RequestParam(required = false) Integer qcStatus,
                                           @RequestParam(required = false) String startDate,
                                           @RequestParam(required = false) String endDate) {
        Page<Map<String, Object>> page = new Page<>(pageNum, pageSize);
        return productionReportingService.pageWithJoin(page, reportNo, processName, processCode,
                relatedWorkOrder, username, workGroup, qcStatus, startDate, endDate);
    }

    @GetMapping("/{id}")
    public Map<String, Object> getById(@PathVariable("id") Long id) {
        return productionReportingService.getDetailById(id);
    }

    @PostMapping("/add")
    public boolean add(@RequestBody ProductionReporting productionReporting) {
        return productionReportingService.addProductionReporting(productionReporting);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody ProductionReporting productionReporting) {
        return productionReportingService.updateProductionReporting(productionReporting);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return productionReportingService.deleteById(id);
    }
}
